package com.nageoffer.shortLink.admin.controller;


import com.nageoffer.shortLink.admin.common.convention.result.Result;
import com.nageoffer.shortLink.admin.common.convention.result.Results;
import com.nageoffer.shortLink.admin.dto.req.ShortLinkGroupSaveReqDTO;
import com.nageoffer.shortLink.admin.dto.req.ShortLinkGroupSortReqDTO;
import com.nageoffer.shortLink.admin.dto.req.ShortLinkGroupUpdateReqDTO;
import com.nageoffer.shortLink.admin.dto.resp.ShortLinkGroupRespDTO;
import com.nageoffer.shortLink.admin.service.GroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class GroupController {
    private final GroupService groupService;

    @PostMapping("/api/short-link/admin/v1/group")
    public Result<Void> saveGroup(@RequestBody ShortLinkGroupSaveReqDTO requestparam) {
        groupService.saveGroup(requestparam.getName() );
        return Results.success();
    }

    @GetMapping("/api/short-link/admin/v1/group")
    public Result<List<ShortLinkGroupRespDTO>> listGroup() {
        return Results.success(groupService.listGroup());
    }

    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> updateGroup(@RequestBody ShortLinkGroupUpdateReqDTO requestparam) {

        groupService.updateGroup(requestparam);

        return Results.success();

    }

    @DeleteMapping("/api/short-link/admin/v1/group")
    public Result<Void> deleteGroup(@RequestParam String gid) {
        groupService.deleteGroup(gid);
        return Results.success();
    }

    @PostMapping("/api/short-link/admin/v1/group/sort")
    public Result<Void> sortGroup(@RequestBody List<ShortLinkGroupSortReqDTO> requestparam) {
        groupService.sortGroup(requestparam);
        return Results.success();

    }


}
